@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Pages.Event
@using k8s.Models
@using Mapster
@inherits BlazorApp.Pages.Common.DrawerPageBase<k8s.Models.V1ServiceAccount>
@if (ServiceAccount != null)
{
    <ServiceAccountAction Item="ServiceAccount" MenuMode="MenuMode.Horizontal"></ServiceAccountAction>
    <Divider Orientation="left" Style="font-weight:bold">@L["Metadata"]</Divider>
    <MetadataView Item="ServiceAccount.Metadata" ExplainFieldPrefix="serviceAccount"></MetadataView>
    <Divider Orientation="left" Style="font-weight:bold">@L["Spec"]</Divider>
    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["AutomountServiceAccountToken"] Item="@ServiceAccount.AutomountServiceAccountToken"
                            ExplainField="serviceAccount.automountServiceAccountToken">
        </PropertySimpleView>
        @if (ServiceAccount.ImagePullSecrets is { Count: > 0 })
        {
            <HTableColumn Title=@L["ImagePullSecrets"] ExplainField="serviceAccount.imagePullSecrets">
                @foreach (var secret in ServiceAccount.ImagePullSecrets)
                {
                    <ColorfulTag>@secret.Name</ColorfulTag>
                }
            </HTableColumn>
        }
        @if (ServiceAccount.Secrets is { Count: > 0 })
        {
            <HTableColumn Title=@L["Secrets"] ExplainField="serviceAccount.secrets">
                @foreach (var secret in ServiceAccount.Secrets)
                {
                    <RefView Ref="secret" FullView="true"></RefView>
                }
            </HTableColumn>
        }


    </HTable>
    @if (RoleRefs is { Count: > 0 } || ClusterRoleRefs is { Count: > 0 })
    {
        <Divider Orientation="left" Style="font-weight:bold">@L["Had Roles"]</Divider>
        <HTable>

            @if (RoleRefs is { Count: > 0 })
            {
                <HTableColumn Title=@L["Roles"]>
                    @foreach (var role in RoleRefs)
                    {
                        <RefView FullView="true" Ref="role.Adapt<V1ObjectReference>()"></RefView>
                    }
                </HTableColumn>
            }


            @if (ClusterRoleRefs is { Count: > 0 })
            {
                <HTableColumn Title=@L["ClusterRoles"]>
                    @foreach (var role in ClusterRoleRefs)
                    {
                        <RefView FullView="true" Ref="role.Adapt<V1ObjectReference>()"></RefView>
                    }
                </HTableColumn>
            }

        </HTable>
    }

    <MiniEventListView Uid="@ServiceAccount.Metadata.Uid"></MiniEventListView>
}
